package com.thread.test;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ThreadLocalRandom;

@Slf4j(topic = "c.test10")
class test10 {
    static boolean flag1=false;
    static boolean flag2=false;
    public test10() {

    }
    public void first(Runnable printFirst)  {

        // printFirst.run() outputs "first". Do not change or remove this line.
        synchronized (this){
            log.debug("lock");
            printFirst.run();
            flag1=true;
            this.notifyAll();
        }

    }

    public void second(Runnable printSecond)  {

        // printSecond.run() outputs "second". Do not change or remove this line.

        synchronized (this){
            log.debug("lock");
            while(!flag1){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            log.debug("出来了");
            printSecond.run();
            flag2=true;
            this.notifyAll();

        }

    }

    public void third(Runnable printThird)  {

        // printThird.run() outputs "third". Do not change or remove this line.
        synchronized (this){
            log.debug("lock");
            while(!flag2||!flag1){
                try {
                    this.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            log.debug("出来了");
            printThird.run();
        }
    }

    public static void main(String[] args)  {
        test10 test=new test10();

    }
}